const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const FileManagerPlugin = require('filemanager-webpack-plugin');

module.exports = {
    entry: {
        '/yjfk/yjfkYdd/yjfkYdd': './yjfk/yjfkYdd/src/index.js',
    },
    output: {
        path: __dirname,
        filename: '[name].js',
    },
    target: ['web', 'es5'], // webpack 将生成 web 平台的运行时代码，并且只使用 ES5 相关的特性
    mode: 'development', // 设置mode [production/development]
    plugins: [
        // 头部添加版本号
        new webpack.BannerPlugin('version:' + _genVersion()),

        // 指定把打包文件复制到指定编译路径
        new FileManagerPlugin({
            events: {
                onEnd: {
                    copy: [
                        { source: './yjfk/yjfkYdd/yjfkYdd.js', destination: '../../../../target/classes/static/yjfk/yjfkYdd/yjfkYdd.js' }
                    ]
                }
            }
        })
    ],
    optimization: {
        minimize: true,
        minimizer: [
            new TerserPlugin({
                extractComments: false // 不要将注释剥离到单独的文件中
            })
        ]
    }
};

// 生成版本号（当前时间）
function _genVersion() {
    var date_ = new Date();
    var year = date_.getFullYear();
    var month = date_.getMonth() + 1;
    var day = date_.getDate();
    if (month < 10) month = '0' + month;
    if (day < 10) day = '0' + day;

    var hours = date_.getHours();
    var mins = date_.getMinutes();
    var secs = date_.getSeconds();
    var msecs = date_.getMilliseconds();
    if (hours < 10) hours = '0' + hours;
    if (mins < 10) mins = '0' + mins;
    if (secs < 10) secs = '0' + secs;
    if (msecs < 10) secs = '0' + msecs;
    return year + '-' + month + '-' + day + ' ' + hours + ':' + mins;
}